package tests;
import meal.*;
import java.util.*;
import util.*;
import java.io.*;

/*Margarita Lee:mleeli | Updated: 11.28.11 -Created MeaTestCase2.
 */

/**
 * A TestCase that calls Meal,  Ingredient and Directions classes to test
 * them out with given inputs by using Scanner and print them out with mealFormatting and save them in a file.
 *
 *<p> MealTestCase2 is the same as MealTestCase1 with the exception that it formats the output of the meal.
 *and saves it to a file of the same name that the meal.
 */

//Last updated: 11.20.11
public class MealTestCase2{

	/**
	 * Create a main method with Scanner, two for loops & arrays
	 * (one for Ingredients, another for Directions), where rating is
	 * in the range(0.0 -1.0).
	 */
	//Last updated: 11.28.11

	public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		boolean truth = true;
		//Ask for the user to the rating of the meal, its name, the
		//name of ingredients for the meal.
		System.out.print("Name the rating: ");
		String rating = s.nextLine();
		System.out.print("Name of the meal: ");
		String name = s.nextLine();
		System.out.print("How many ingredients are you going to use? ");
		int numIngr = Integer.valueOf(s.nextLine());
		Ingredient ingredients[] = new Ingredient[numIngr];
		String qty, units, ingr;
		//For loop that continues to run for as many times as the user set
		//the number of Ingredients to be used.
		//It ask the user to type the quantity, units and ingredient name.
		for(int i = 0; i <numIngr; i++){
			System.out.print("Name the Quantity of the Ingredient: ");
			qty = s.nextLine();
			System.out.print("Name the Units of the Ingredient: ");
			units = s.nextLine();
			System.out.print("Name the Ingredient: ");
			ingr = s.nextLine();
			//Saves the ingredients with the respective quantity and units into
			//the ingredients array.
			ingredients[i]=new Ingredient(ingr, Integer.valueOf(qty),units);
		}
		//Ask the user how many steps will the direction have.
		System.out.print("How many steps will your meal have? ");
		int numStep = Integer.valueOf(s.nextLine());
		Direction directions[] = new Direction[numStep];
		System.out.println("Name the steps for this meal: ");
		String step;
		//For loop will run as long as the number of steps the user set.
		for(int i = 0; i <Integer.valueOf(numStep); i++){
			step = s.nextLine();
			//Saves the direction to the directions array.
			directions[i] = new Direction(step);
		}
		//Creates a new meal with the name, ingredients, directions and rating given by the user.
		Meal meal = new Meal(
				name,
				ingredients,
				directions,
				Double.valueOf(rating));
		//Save the formatted version of meal as a String str.
		String str = MealFormatting.formatMeal(meal);
		//Print the string and writes it to a file of the meal's name by calling IO.write.
		System.out.println(str);
		IO.write(name, str);
	}
}
